package com.own.demo.长沙空中路网格子.Thread;

import com.alibaba.fastjson.JSONArray;
import com.own.demo.utils.DecimalFormatUtils;
import org.locationtech.jts.geom.Coordinate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;

/**
 * 线程启用接口
 *
 * @author heguanglong
 * @date 2023/6/13
 */
public class LonLat6Thread implements Runnable {
    private static Logger log = LoggerFactory.getLogger(LonLat6Thread.class);
    private JSONArray allPoints;
    private CountDownLatch countDownLatch;


    public LonLat6Thread(CountDownLatch countDownLatch, JSONArray coordinates) {
        this.allPoints = coordinates;
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        try {
            int row = allPoints.size();
            JSONArray temp = new JSONArray(row);
            for (int i = 0; i < row; i++) {
                JSONArray array = allPoints.getJSONArray(i);
                double lon = DecimalFormatUtils.getDecimalFormatUtils(array.getDouble(0));
                double lat = DecimalFormatUtils.getDecimalFormatUtils(array.getDouble(1));
                array.clear();
                array.add(lon);
                array.add(lat);
                temp.add(array);
            }
            allPoints.clear();
            allPoints.addAll(temp);
        } catch (Exception e) {
            e.printStackTrace();
        }
        countDownLatch.countDown();
    }

}
